1656C - Make Equal With Mod - CodeForces Solution


math number theory sortings

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    c1 = 0
    for i in a:
        if i==1:
            c1+=1
            break
    if c1==0:
        print("yes")
        continue
    c = 0
    for i in range(n-1):
        if a[i+1] == a[i]+1:
            c+=1
            break
    if c>0:
        print("no")
        continue
    print("yes")

C++ Code:

/******Code******/
//    CODE BY A_K ;)

//		(⌐■_■)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define pop pop_back()
#define le(i,a,b) for(i=a;i<=b;++i)
#define de(j,a,b) for(j=a;j>=b;--j)
#define arsort(arr,n) sort(arr,arr+n)
#define rvarsort(arr,n) sort(arr,arr+n,greater<ll>())
#define vi vector<ll>
#define all(a) (a).begin(),(a).end()
#define vecsort(vec) sort(vec.begin(),vec.end())
#define Mod 10e9+7
ll md=Mod;
bool primes[1000001]; //For sieve
/*Ascii Values!!:
A=65,Z=90,a=97,z=122*/

//*****Arr-Input****
void takearr(ll arr[],ll n)
{
    for(ll i=0;i<n;i++)
        cin>>arr[i];
}

//********Sieve******
/*void sieve(){

    memset(primes, true, sizeof(primes));
    primes[1] = false; primes[0] = false;
    for(size_t i = 2; i*i <= Mod; i++){
        if(primes[i]){
            for(size_t j = i*i; j < Mod; j += i)
            primes[j] = false;
}}}*/

//******FACTORS*******
void allfacts(ll n, vector<ll> &v){
    for(ll i=1; i<=sqrt(n); ++i){
        if(n%i==0){
        if(n/i==i)
            v.push_back(i);
        else{
            v.push_back(i);
            v.push_back(n/i);
        }
}}}
bool checkarr(ll arr[],ll n)
{
    ll i;
    ll chk=arr[0];
    le(i,1,n-1)
    {
        if(arr[i]!=chk)
            return false;
    }
    return true;
}
//******SOLVER******
void solver(){
ll i,n,j,mod=Mod;
cin>>n;
bool one=0,zero=0;
ll arr[n];
le(i,0,n-1)
{
    cin>>arr[i];
    if(arr[i]==1)
        one=true;
    if(arr[i]==0)
        zero=true;
}
if(checkarr(arr,n))
{
    cout<<"YES\n";
    return;
}
if(one && zero){
    cout<<"NO\n"; return;
}
if(one)
{
    sort(arr,arr+n);
    //bool chk=false;
    le(i,1,n-1)
    {
        if(arr[i]-arr[i-1]==1){
           // chk=true;
           cout<<"NO\n";
           return;
        }
    }
    cout<<"YES\n";
    return;
}
cout<<"YES\n";
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    t=1;
    cin>>t;
    while(t--)
        solver();
return 0;
}


Comments

Submit
0 Comments
More Questions

240. Search a 2D Matrix II
238. Product of Array Except Self
229. Majority Element II
222. Count Complete Tree Nodes
215. Kth Largest Element in an Array
198. House Robber
153. Find Minimum in Rotated Sorted Array
150. Evaluate Reverse Polish Notation
144. Binary Tree Preorder Traversal
137. Single Number II
130. Surrounded Regions
129. Sum Root to Leaf Numbers
120. Triangle
102. Binary Tree Level Order Traversal
96. Unique Binary Search Trees
75. Sort Colors
74. Search a 2D Matrix
71. Simplify Path
62. Unique Paths
50. Pow(x, n)
43. Multiply Strings
34. Find First and Last Position of Element in Sorted Array
33. Search in Rotated Sorted Array
17. Letter Combinations of a Phone Number
5. Longest Palindromic Substring
3. Longest Substring Without Repeating Characters
1312. Minimum Insertion Steps to Make a String Palindrome
1092. Shortest Common Supersequence
1044. Longest Duplicate Substring
1032. Stream of Characters